﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using JKF.BusinessLayer.BLL;
using JKF.Substructure;

namespace JKF.Web.Customer
{
    public partial class Customer_Info : PageBase
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        public string Photo_Url
        {
            get
            {
                var customerKey = P("customerKey");
                bllCUSTOMER c = new bllCUSTOMER();
                string url = "";
                url = c.GetPhotoUrlByKey(customerKey);
                if (url == "")
                    url = "../App_Themes/nophoto.png";
                return url;
            }
        }
        public string CustomerInfo
        {
            get
            {
                var customerKey = P("customerKey");
                if (customerKey.IsGuidB())
                {
                    var levelMgr = new bllDIC_LEVEL();
                    var bllCustomer = new bllCUSTOMER();
                    var bllMem = new bllCUSTOMER_MEMORIALDAY();
                    var groupMgr = new bllDIC_GROUP();
                    var areaMgr = new bllDIC_AREA();
                    var bllDisease = new bllCUSTOMER_DISEASE();
                    var customer = bllCustomer.GetModel(customerKey.ToGuid());
                    var level = customer == null ? null : levelMgr.GetModel(customer.LEVEL_CODE);
                    var group = customer == null ? null : groupMgr.GetModel(customer.GROUP_KEY);
                    var prov = (customer != null && !string.IsNullOrEmpty(customer.AREA_CODE)) ? areaMgr.GetModel(customer.AREA_CODE.Substring(0, 2) + "0000") : null;
                    var city = (customer != null && !string.IsNullOrEmpty(customer.AREA_CODE)) ? areaMgr.GetModel(customer.AREA_CODE.Substring(0, 4) + "00") : null;
                    var area = (customer != null && !string.IsNullOrEmpty(customer.AREA_CODE)) ? areaMgr.GetModel(customer.AREA_CODE) : null;
                    return new
                    {
                        Customer = customer == null ? null : new
                            {
                                CUSTOMER_KEY = customer.CUSTOMER_KEY.ToString(),
                                CARD_NO = customer.CARD_NO,
                                NAME = customer.NAME,
                                ID_CARD = customer.ID_CARD,
                                SEX = customer.SEX == "1" ? "男" : "女",
                                MOBILE = customer.MOBILE,
                                PHONE = customer.PHONE,
                                REFEREE_CARD = customer.REFEREE_CARD,
                                REFEREE = customer.REFEREE,
                                ADDRESS = customer.ADDRESS,
                                POSTAL_CODE = customer.POSTAL_CODE,
                                EMAIL = customer.EMAIL,
                                AREA = (prov != null ? prov.NAME : "") + (city != null ? city.NAME : "") + (area != null ? area.NAME : ""),
                                DISEASE = customer.DISEASE,
                                GIVE_POINTS = customer.GIVE_POINTS,
                                CONSUME_POINTS = customer.CONSUME_POINTS,
                                PWD = customer.PWD,
                                MEMO = customer.MEMO,
                                LEVEL_CODE = customer.LEVEL_CODE,
                                BIRTHDAY = customer.BIRTHDAY.ToShortDateLineFormat(),
                                LEVEL_NAME = level != null ? level.NAME : "",
                                AVAIPOINTS = customer.GIVE_POINTS + customer.CONSUME_POINTS,
                                STORED_MONEY = customer.STORED_MONEY,
                                DATE_CREATE = customer.DATE_CREATE.ToString("yyyy-MM-dd"),
                                GROUP_NAME = group != null ? group.NAME : "",
                                STATUS_NAME = (customer.STATUS == "1" ? "有效" : (customer.STATUS == "9" ? "已删除" : "")),
                                TITLE = customer.TITLE,
                                FAMILY = customer.FAMILY
                            },
                        MemoryDay = bllMem.GetListArray(string.Format(" CUSTOMER_KEY='{0}'", customerKey)),
                        Disease = (from c in bllDisease.GetListArray(string.Format(" CUSTOMER_KEY='{0}'", customerKey)) select new { Code = c.CODE, Name = c.NAME }).ToList()

                    }.ToJson();
                }
                return "null";
            }
        }
    }
}